package org.mbcorp.sar.dao;

import java.util.List;

import org.mbcorp.sar.model.Operador;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface OperadorDAO extends JpaRepository<Operador, Integer> {
	
	@Query("SELECT o FROM Operador o WHERE o.login = :login")
    public List<Operador> buscarPorLogin(@Param("login") String login);
	
	@Query("SELECT DISTINCT o FROM Operador o, NivelCompetencia n, Experticia x, Fase f WHERE f.id = :idFase AND n.competencia.id IN (SELECT id FROM f.competencias) AND "
			+ "n.id IN (SELECT x.nivelCompetencia.id FROM o.experticias WHERE x.operador.id = o.id)")
    public List<Operador> buscarRecursosDisponibles(@Param("idFase") Integer idFase);
	
	@Query("SELECT o FROM Operador o ORDER BY o.puntajeAcumulado DESC")
    public List<Operador> buscarTodosPorPuntos();

}
